﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ShowPage_webCL : System.Web.UI.Page
{
    Operation operation = new Operation();
    static string infoType = "";
    static string infoKey = "";
    
    static PagedDataSource pds = new PagedDataSource();

    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!IsPostBack)
        {
            infoType = "技术供应信息";

            if (Session["key"] != null)
            {
                //infoKey的意思用语用户快速检索，如果值为空，显示所有招聘供求信息，否则显示查询内容
                infoKey = Convert.ToString(Session["key"]);
                Session["key"] = null;
                BuiltDlOneClass();
                this.DataListBind();
            }
            else
            {
                infoKey = "";
                if (!IsPostBack)
                {
                    BuiltDlOneClass();
                    this.DataListBind();
                }
            }
        }
    }
    public void BuiltDlOneClass()//一级下拉框
    {
        ListItem item = new ListItem();
        item.Text = "..请选择";
        item.Value = "-1";
        dlOneClass.Items.Clear();
        dlOneClass.Items.Add(item);
        DataSet ds = operation.SelectCategoryByPID("0",true); ;//一级类别
        int count = ds.Tables[0].Rows.Count;
        for (int i = 0; i < count; i++)
        {
            item = new ListItem();
            item.Value = ds.Tables[0].Rows[i][0].ToString();
            item.Text = ds.Tables[0].Rows[i][1].ToString();
            dlOneClass.Items.Add(item);
        }
        BuiltDlTwoClass();
    }
    public void BuiltDlTwoClass()//二级下拉框
    {
        ListItem item = new ListItem();
        item.Text = "..请选择";
        item.Value = "-1";
        dlTwoClass.Items.Clear();
        dlTwoClass.Items.Add(item);
        if (dlOneClass.Text.CompareTo("-1") != 0)
        {
            DataSet ds = operation.SelectCategoryByPID(dlOneClass.Text,true); ;//二级类别
            int count = ds.Tables[0].Rows.Count;
            try
            {
                for (int i = 0; i < count; i++)
                {
                    item = new ListItem();
                    item.Value = ds.Tables[0].Rows[i][0].ToString();
                    item.Text = ds.Tables[0].Rows[i][1].ToString();
                    dlTwoClass.Items.Add(item);
                }
            }
            catch (Exception ex) { }
        }
        BuiltDlThreeClass();
    }
    public void BuiltDlThreeClass()//三级下拉框
    {
        ListItem item = new ListItem();
        item.Text = "..请选择";
        item.Value = "-1";
        dlThreeClass.Items.Clear();
        dlThreeClass.Items.Add(item);
        if (dlTwoClass.Text.CompareTo("-1") != 0)
        {
            DataSet ds = operation.SelectCategoryByPID(dlTwoClass.Text,true);//三级类别
            int count = ds.Tables[0].Rows.Count;
            BuildDownList(dlTwoClass.Text, "", "---");//如果分级多于三级，将在该级显示全部余下分类
        }
    }
    public void BuildDownList(string pid, string itH, string dx)//itH为表项前度，dx为递增前度
    {
        DataSet ds = operation.SelectCategoryByPID(pid,true);//一级类别
        int count = ds.Tables[0].Rows.Count;
        string t = itH + dx;//下级前度
        for (int i = 0; i < count; i++)
        {
            ListItem item = new ListItem();
            item.Value = ds.Tables[0].Rows[i][0].ToString();
            item.Text = itH + ds.Tables[0].Rows[i][1].ToString();
            dlThreeClass.Items.Add(item);
            BuildDownList(item.Value, t, dx);
        }
    }
    protected void dlOneClass_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataListBind();
        BuiltDlTwoClass();
    }
    protected void dlTwoClass_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataListBind();
        BuiltDlThreeClass();
    }
    protected void dlThreeClass_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataListBind();
    }
    /// <summary>
    /// 将数据绑定到DataList控件
    /// </summary>
    public void DataListBind()
    {
        string typeid = "-1";
        if (dlOneClass.Text.CompareTo("-1") != 0)
        {
            if (dlTwoClass.Text.CompareTo("-1") == 0)
            {
                typeid = dlOneClass.Text;
            }
            else
            {
                if (dlThreeClass.Text.CompareTo("-1") == 0)
                {
                    typeid = dlTwoClass.Text;
                }
                else
                {
                    typeid = dlThreeClass.Text;
                }
            }
        }
        if (typeid.CompareTo("-1") == 0)
        {
            pds = operation.PageDataListBind(infoType, infoKey, Convert.ToInt32(lblCurrentPage.Text), 10);
        }
        else
        {
            pds = operation.PageDataListBindByTypeTree(infoType, typeid, Convert.ToInt32(lblCurrentPage.Text), 10);
        }
        lnkBtnFirst.Enabled = true;　　　　　　//控件翻页控件都设置为可用
        lnkBtnLast.Enabled = true;
        lnkBtnNext.Enabled = true;
        lnkBtnPrevious.Enabled = true;
        if (lblCurrentPage.Text == "1")　　　//如果当前显示第一页，“第一页”和“上一页”按钮不可用。
        {
            lnkBtnPrevious.Enabled = false;
            lnkBtnFirst.Enabled = false;
        }
        if (lblCurrentPage.Text == pds.PageCount.ToString())　　//如果显示最后一页，“末一页”和“下一页”按钮不可用。
        {
            lnkBtnNext.Enabled = false;
            lnkBtnLast.Enabled = false;
        }
        lblSumPage.Text = pds.PageCount.ToString();　　//实现总页数
        dlFree.DataSource = pds;　　　　　　　　　　　 //绑定数据源
        dlFree.DataKeyField = "id";
        dlFree.DataBind();
    }
    protected void lnkBtnFirst_Click(object sender, EventArgs e)
    {
        lblCurrentPage.Text = "1";
        DataListBind();
    }
    protected void lnkBtnPrevious_Click(object sender, EventArgs e)
    {
        lblCurrentPage.Text = (Convert.ToInt32(lblCurrentPage.Text) - 1).ToString();
        DataListBind();
    }
    protected void lnkBtnNext_Click(object sender, EventArgs e)
    {
        lblCurrentPage.Text = (Convert.ToInt32(lblCurrentPage.Text) + 1).ToString();
        DataListBind();
    }
    protected void lnkBtnLast_Click(object sender, EventArgs e)
    {
        lblCurrentPage.Text = lblSumPage.Text;
        DataListBind();
    }
}
